package lg.minecraft.plugin.testeconomy.command;

import lg.minecraft.plugin.testeconomy.TestEconomy;
import lg.minecraft.plugin.testeconomy.storage.BaseStorage;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

/**
 * @author langle__
 * @version 1.0
 */
public abstract class SubCommand {

    public abstract String getName();

    public abstract void onCommand(CommandSender sender, String[] args);

    public BaseStorage getStorage() {
        return TestEconomy.getStorage();
    }

    public Double argToDouble(String arg) {
        double amount;
        try {
            amount = Double.parseDouble(arg);
        } catch (NumberFormatException e) {
            return null;
        }
        if (amount <= 0) {
            return 0.0D;
        }
        return amount;
    }

    public Player argToPlayer(String arg) {
        return Bukkit.getPlayer(arg);
    }

}
